$(function() {
    //猜你喜欢
    var flag = false;
    var pageNum = 1;
    function loadLikeProduct(){
        if (flag) return false;
        $.ajax({
            url: domain.test + "/getlike",
            // url: domain.online + "/api/index/like",
            type: 'get',
            data: 'pageNum=' + pageNum,
            dataType: 'json',
            beforeSend: function () {
                flag = true;
            },
            success: function (response) {
                var likeProductDetail = response.data.data;
                // var likeProductDetail = response.data;
                if (pageNum == 1) {
                    $('.itemBox').html(template('itemBox', { productList: likeProductDetail.plist }));
                } else {
                    $('.itemBox').append(template('itemBox', { productList: likeProductDetail.plist }));
                }
                pullmaster.pullDownSuccess();       //刷新成功
                if (likeProductDetail.plist.length < 10 || likeProductDetail.plist.length === 0) {
                    pullmaster.pullUpDone();        //到底啦
                    $(".bb_pull-up").css({"display":"none"});
                    $(".end").css({"display":"block"});
                }
                ++pageNum;
                flag = false;
            },
            error: function () {
                pullmaster.pullDownFailed();        //刷新失败
                pullmaster.pullUpFailed();          //数据加载失败
            }
        })
    }
    // 下拉刷新上滑分页加载
    var pullmaster = new Pull($('.likeProduct'), {
        onPullUp: function () {
            loadLikeProduct();
        },
        onPullDown:function() {
            pageNum = 1;
            loadLikeProduct();
        }
    });
    //查看详情
    $(".itemBox").on("click",".likeProductItem",function(){
        var pId = $(this).attr("data-id");
        location.href = "http://wap.pusai.net/product.html?id=" + pId;
    })
})